<?php

namespace app\admin\controller;

class CompanyDetail extends Backend
{
    protected $model = null;

    protected $needSelectCompany = true;
    protected $beforeActionList = [
        'getCurrentCompany',
        'validateCompany' => ['only' => ['delete', 'edit']],
    ];

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\CompanyDetail();
    }

    public function index()
    {
        $list = $this->model
            ->with($this->with ? $this->with : null)
            ->where("company_id", $this->company->id)
            ->order('sort', 'asc')
            ->paginate();
        $this->assign('list', $list);
        return $this->fetch();
    }


    protected function validateCompany()
    {
        if (is_null($this->company)) {
            $this->error('请选择企业');
        }
        $entity = $this->model->find(input('id'));
        if ($entity->company_id != $this->company->id) {
            $this->error('非法操作');
        }
    }

}
